home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / TEST / GLUT / TEST5.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.8 KB  |  134 lines

  1.  
  2. /* Copyright (c) Mark J. Kilgard, 1994. */
  3.  
  4. /* This program is freely distributable without licensing fees 
  5.    and is provided without guarantee or warrantee expressed or 
  6.    implied. This program is -not- in the public domain. */
  7.  
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <GL/glut.h>
  11.  
  12. GLfloat comp;
  13. int mask = 0;
  14.  
  15. void
  16. display(void)
  17. {
  18.   glClear(GL_COLOR_BUFFER_BIT);
  19.   glFlush();
  20.   mask |= 1 << glutGetWindow();
  21. }
  22.  
  23. void
  24. timeout(int value)
  25. {
  26.   if (value != 1) {
  27.     printf("FAIL: test5\n");
  28.     exit(1);
  29.   }
  30.   if (mask != 0x6) {
  31.     printf("FAIL: test5\n");
  32.     exit(1);
  33.   }
  34.   printf("PASS: test5\n");
  35.   exit(0);
  36. }
  37.  
  38. int
  39. main(int argc, char **argv)
  40. {
  41.   int win1, win2, size;
  42.   GLint isIndex;
  43.  
  44.   glutInit(&argc, argv);
  45.   glutInitDisplayMode(GLUT_INDEX);
  46.   if (!glutGet(GLUT_DISPLAY_MODE_POSSIBLE)) {
  47.     printf("UNRESOLVED: test5 (your OpenGL lacks color index support)\n");
  48.     exit(0);
  49.   }
  50.   glutInitWindowPosition(45, 45);
  51.   win1 = glutCreateWindow("CI test 1");
  52.   glGetIntegerv(GL_INDEX_MODE, &isIndex);
  53.   if (isIndex == 0) {
  54.     printf("FAIL: test5\n");
  55.     exit(1);
  56.   }
  57.   size = glutGet(GLUT_WINDOW_COLORMAP_SIZE);
  58.   if (size <= 1 || size > (1 << glutGet(GLUT_WINDOW_BUFFER_SIZE))) {
  59.     printf("FAIL: test5\n");
  60.     exit(1);
  61.   }
  62.   glutSetColor(2, 1.0, 3.4, 0.5);
  63.   comp = glutGetColor(2, GLUT_RED);
  64.   if (comp != 1.0) {
  65.     printf("FAIL: test5\n");
  66.     exit(1);
  67.   }
  68.   comp = glutGetColor(2, GLUT_GREEN);
  69.   if (comp != 1.0) {
  70.     printf("FAIL: test5\n");
  71.     exit(1);
  72.   }
  73.   comp = glutGetColor(2, GLUT_BLUE);
  74.   if (comp != 0.5) {
  75.     printf("FAIL: test5\n");
  76.     exit(1);
  77.   }
  78.   glutInitWindowPosition(450, 450);
  79.   win2 = glutCreateWindow("CI test 2");
  80.   glutCopyColormap(win1);
  81.   if (glutGetColor(2, GLUT_RED) != 1.0) {
  82.     printf("FAIL: test5\n");
  83.     exit(1);
  84.   }
  85.   if (glutGetColor(2, GLUT_GREEN) != 1.0) {
  86.     printf("FAIL: test5\n");
  87.     exit(1);
  88.   }
  89.   if (glutGetColor(2, GLUT_BLUE) != 0.5) {
  90.     printf("FAIL: test5\n");
  91.     exit(1);
  92.   }
  93.   glutSetColor(2, -1.0, 0.25, 0.75);
  94.   glutSetWindow(win1);
  95.   if (win1 != glutGetWindow()) {
  96.     printf("FAIL: test5\n");
  97.     exit(1);
  98.   }
  99.   glutDisplayFunc(display);
  100.   if (glutGetColor(2, GLUT_RED) != 1.0) {
  101.     printf("FAIL: test5\n");
  102.     exit(1);
  103.   }
  104.   if (glutGetColor(2, GLUT_GREEN) != 1.0) {
  105.     printf("FAIL: test5\n");
  106.     exit(1);
  107.   }
  108.   if (glutGetColor(2, GLUT_BLUE) != 0.5) {
  109.     printf("FAIL: test5\n");
  110.     exit(1);
  111.   }
  112.   glutSetWindow(win2);
  113.   if (win2 != glutGetWindow()) {
  114.     printf("FAIL: test5\n");
  115.     exit(1);
  116.   }
  117.   if (glutGetColor(2, GLUT_RED) != 0.0) {
  118.     printf("FAIL: test5\n");
  119.     exit(1);
  120.   }
  121.   if (glutGetColor(2, GLUT_GREEN) != 0.25) {
  122.     printf("FAIL: test5\n");
  123.     exit(1);
  124.   }
  125.   if (glutGetColor(2, GLUT_BLUE) != 0.75) {
  126.     printf("FAIL: test5\n");
  127.     exit(1);
  128.   }
  129.   glutTimerFunc(1500, timeout, 1);
  130.   glutDisplayFunc(display);
  131.   glutMainLoop();
  132.   return 0;             /* ANSI C requires main to return int. */
  133. }
  134.